﻿using ProCP.Sim;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProCP
{
    public partial class Form2 : Form
    {
        public int ReturnValue1 { get; set; }

        Sim.Simulation simulation;
        int SelectedCross;
        
        public Form2()
        {
            InitializeComponent();
             simulation = new Simulation(
                new Size(2,1),
                new Point(5, 5),
                new Size(300, 300));
            simulation.AddCrossing(0, 1);
            simulation.AddCrossing(1, 2);
            SelectedCross = -1;
            
        }

        private void Form2_Paint(object sender, PaintEventArgs e)
        {
            
            simulation.Draw(e.Graphics);
        }

        private void Form2_MouseClick(object sender, MouseEventArgs e)
        {
            using (Graphics g = this.label2.CreateGraphics())
            {
                this.Refresh();
                SelectedCross = simulation.MouseClickToPossition(e.Location);
                if (SelectedCross >= 0)
                {
                    simulation.DrawSelectedRectangle(g, SelectedCross);
                }
                else
                {
                    SelectedCross = -1;
                }
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            
            if (SelectedCross < 0)
            {
                MessageBox.Show("You have not selected crossing!!!");
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                this.ReturnValue1 = SelectedCross;
                this.Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form2_DoubleClick(object sender, MouseEventArgs e)
        {
            if (SelectedCross >= 0)
            {
                this.DialogResult = DialogResult.OK;
                this.ReturnValue1 = SelectedCross;
                this.Close();
            }
        }
    }
}
